package cn.openea.perpartner.meily.web.entity.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.List;

/**
 * @author ysk
 * @version 1.0.1
 * @Description 收益记录查询Vo
 * @createTime 2023年03月22日 16:24:00
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RevenueRecordsSearchVo {
    /**
     * 查询时间段 默认单月
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate timePeriod = LocalDate.now();

    private List<String> ids;

    @Max(1)
    @Min(0)
    private Short batchType = 0;

    public boolean byIds() {
        return this.batchType == 0;
    }

    public void setTimePeriod(LocalDate timePeriod) {
        if (timePeriod == null) {
            this.timePeriod = LocalDate.now();
            return;
        }
        this.timePeriod = timePeriod;
    }

    public boolean isSearchHistory() {
        // 获取当前时间
        LocalDate now = LocalDate.now();
        // 获取本月低和本月初的时间
        LocalDate startOfThisMonth = now.withDayOfMonth(1);
        LocalDate endOfThisMonth = now.with(TemporalAdjusters.lastDayOfMonth());
        if (timePeriod.isAfter(startOfThisMonth) && timePeriod.isBefore(endOfThisMonth.plusDays(1))) {
            return false;
        } else {
            // 更早之前
            return true;
        }
    }
}
